package converters;

import controller.LeaveRemote;
import dtos.LeaveDTO;
import dtos.LeaveStatusDTO;
import dtos.LeaveTypeDTO;
import dtos.UserDTO;
import utils.UserDAORemote;

import java.io.Serializable;
import java.util.Date;

public class LeaveModel implements Serializable {

    private LeaveDTO leaveDTO;
    private UserDTO userDTO;
    private LeaveTypeDTO leaveTypeDTO;
    private LeaveStatusDTO leaveStatusDTO;

    public LeaveModel(LeaveDTO leaveDTO, LeaveRemote leaveRemote, UserDAORemote userDAORemote) {
        this.leaveDTO = leaveDTO;
        if (leaveDTO.getUser() != 0) {
            this.userDTO = userDAORemote.getUser(leaveDTO.getUser());
        }
        if (leaveDTO.getType() != 0) {
            this.leaveTypeDTO = leaveRemote.getLeaveTypeById(leaveDTO.getType());
        }
        if (leaveDTO.getStatus() != 0) {
            this.leaveStatusDTO = leaveRemote.getLeaveStatusById(leaveDTO.getStatus());
        }
    }

    public int getId() {
        return leaveDTO.getId();
    }

    public void setId(int id) {
        this.leaveDTO.setId(id);
    }

    public LeaveDTO getLeaveDTO() {
        return leaveDTO;
    }

    public void setLeaveDTO(LeaveDTO leaveDTO) {
        this.leaveDTO = leaveDTO;
    }

    public UserDTO getUserDTO() {
        return userDTO;
    }

    public void setUserDTO(UserDTO userDTO) {
        this.leaveDTO.setUser(userDTO.getId());
        this.userDTO = userDTO;
    }

    public LeaveTypeDTO getLeaveTypeDTO() {
        return leaveTypeDTO;
    }

    public void setLeaveTypeDTO(LeaveTypeDTO leaveTypeDTO) {
        this.leaveDTO.setType(leaveTypeDTO.getId());
        this.leaveTypeDTO = leaveTypeDTO;
    }

    public LeaveStatusDTO getLeaveStatusDTO() {
        return leaveStatusDTO;
    }

    public void setLeaveStatusDTO(LeaveStatusDTO leaveStatusDTO) {
        this.leaveDTO.setStatus(leaveStatusDTO.getId());
        this.leaveStatusDTO = leaveStatusDTO;
    }

    public Date getFrom() {
        return leaveDTO.getFrom();
    }

    public void setFrom(Date from) {
        this.leaveDTO.setFrom(from);
    }

    public Date getUntil() {
        return leaveDTO.getUntil();
    }

    public void setUntil(Date until) {
        this.leaveDTO.setUntil(until);
    }

    public String getReason() {
        return leaveDTO.getReason();
    }

    public void setReason(String reason) {
        this.leaveDTO.setReason(reason);
    }
}
